GO
/****** Object:  Table [dbo].[tblPageEntity]    Script Date: 06/01/2009 19:03:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblPageEntity](
	[pkPageGUID] [uniqueidentifier] NOT NULL,
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[EntityType] [int] NOT NULL,
	[SiteID] [int] NOT NULL,
 CONSTRAINT [PK_tblPageEntity] PRIMARY KEY CLUSTERED 
(
	[pkPageGUID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY],
 CONSTRAINT [IX_tblPageEntity] UNIQUE NONCLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]


GO
/****** Object:  StoredProcedure [dbo].[spAddPageEntity]    Script Date: 06/01/2009 18:59:44 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[spAddPageEntity]
@pageGuid UNIQUEIDENTIFIER,
@entityType INT,
@siteID INT
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    INSERT INTO tblPageEntity(pkPageGUID, EntityType, SiteID) VALUES (@pageGuid, @entityType, @siteID)
	SELECT SCOPE_IDENTITY()

END


GO
/****** Object:  StoredProcedure [dbo].[spGetPageEntities]    Script Date: 06/01/2009 19:00:23 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[spGetPageEntities]
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    SELECT * FROM tblPageEntity ORDER BY ID
END


GO
/****** Object:  StoredProcedure [dbo].[spGetPageEntitiesByType]    Script Date: 06/01/2009 19:01:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[spGetPageEntitiesByType]
@entityType INT
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    SELECT * FROM tblPageEntity WHERE EntityType = @entityType ORDER BY ID
END

GO
/****** Object:  StoredProcedure [dbo].[spGetPageEntityByID]    Script Date: 06/01/2009 19:01:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[spGetPageEntityByID]
@ID INT
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    SELECT * FROM tblPageEntity WHERE ID = @ID
END


GO
/****** Object:  StoredProcedure [dbo].[spGetPageEntityByPageGUID]    Script Date: 06/01/2009 19:02:04 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[spGetPageEntityByPageGUID]
@pageGUID UNIQUEIDENTIFIER
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    SELECT * FROM tblPageEntity WHERE pkPageGUID = @pageGUID
END


GO
/****** Object:  StoredProcedure [dbo].[spRemovePageEntity]    Script Date: 06/01/2009 19:02:21 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[spRemovePageEntity]
@ID int
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    DELETE FROM tblPageEntity WHERE ID = @ID
END


GO
/****** Object:  StoredProcedure [dbo].[spUpdatePageEntity]    Script Date: 06/01/2009 19:02:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[spUpdatePageEntity]
@ID INT,
@entityType INT,
@siteID INT
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    UPDATE tblPageEntity SET EntityType = @entityType, SiteID = @siteID
	WHERE ID = @ID
END
